package servlet.Person;

import service.person.PersonService;
import service.person.PersonServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class twoBM extends HttpServlet {
    private static final long serialVersionUID = 1L;
    PersonService personService = new PersonServiceImpl();

    public twoBM() {
        super();
        // TODO Auto-generated constructor stub
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        String name1 = request.getParameter("name1");
        String sex1 = request.getParameter("sex1");
        int age1 = Integer.parseInt(request.getParameter("age1"));
        String idcard1 = request.getParameter("idcard1");

        String name2 = request.getParameter("name2");
        String sex2 = request.getParameter("sex2");
        int age2 = Integer.parseInt(request.getParameter("age2"));
        String idcard2 = request.getParameter("idcard2");

        String name3 = request.getParameter("name3");
        String sex3 = request.getParameter("sex3");
        int age3 = Integer.parseInt(request.getParameter("age3"));
        String idcard3 = request.getParameter("idcard3");

        String phone = request.getParameter("phone");

        int i = personService.twoPerson(name1,sex1,age1,idcard1,name2,sex2,age2,idcard2,name3,sex3,age3,idcard3,phone);
        if (i > 0) {

            response.sendRedirect(request.getContextPath() + "/end.jsp?msg=1");
        } else {
            response.sendRedirect(request.getContextPath() + "/end.jsp?msg=0");
        }
    }
}